package ve.usb;

import DBMS.DataBaseManager;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.*;

import ve.usb.cohesion.runtime.CohesionAction;


/**
 * 
 */
public class AccionesGestionar_HorarioE extends CohesionAction {
    
/**
     * Acci??n llamada por Struts para ejecutar la acci??n A_PreGestion_HorarioE.
     * 
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward A_PreGestion_HorarioE(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String[] SALIDAS = {"V_Gestion_HorarioE", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
        

        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Acci??n llamada por Struts para ejecutar la acci??n A_PreAgregar_HorarioE.
     * 
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward A_PreAgregar_HorarioE(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String[] SALIDAS = {"V_Agregar_HorarioE", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
        

        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Acci??n llamada por Struts para ejecutar la acci??n A_Agregar_HorarioE.
     * 
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward A_Agregar_HorarioE(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String[] SALIDAS = {"A_Consultar_HorarioE", "V_Agregar_HorarioE", };
        final int SALIDA_0 = 0;
        final int SALIDA_1 = 1;

        int salida = 0;
        ActionErrors errors = new ActionErrors();
        Horario fHorario = (Horario)form;
        DataBaseManager dbms = DataBaseManager.getInstance();
        boolean registro = dbms.registrarHorario(fHorario);
        if ( registro ) {
            salida = SALIDA_0;
        } else {
            errors.add("horario", new ActionMessage("errors.horario.dual"));
            saveErrors(request,errors);
            salida = SALIDA_1;
        }
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Acci??n llamada por Struts para ejecutar la acci??n A_Consultar_HorarioE.
     * 
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward A_Consultar_HorarioE(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String[] SALIDAS = {"V_Consultar_HorarioE", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
        DataBaseManager dbms = DataBaseManager.getInstance();
        ArrayList<Horario> hors = dbms.cargarHorario();
        request.getSession().setAttribute("hor",hors);

        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Acci??n llamada por Struts para ejecutar la acci??n A_PreModificar_HorarioE.
     * 
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward A_PreModificar_HorarioE(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        final String[] SALIDAS = {"V_Modificar_HorarioE", };
        final int SALIDA_0 = 0;
        int salida = SALIDA_0;
        EliminarHorario rf = (EliminarHorario) form;
        DataBaseManager dbms = DataBaseManager.getInstance();
        Horario h = dbms.elegirHorario(rf);
        request.getSession().setAttribute("hora",h);
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Acci??n llamada por Struts para ejecutar la acci??n A_Modificar_HorarioE.
     * 
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward A_Modificar_HorarioE(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String[] SALIDAS = {"A_Consultar_HorarioE", };
        final int SALIDA_0 = 0;
        int salida = SALIDA_0;
        Horario fHorario = (Horario)form;
        DataBaseManager dbms = DataBaseManager.getInstance();
        dbms.modificarHorario(fHorario);
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Acci??n llamada por Struts para ejecutar la acci??n A_Eliminar_HorarioE.
     * 
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward A_Eliminar_HorarioE(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        //Salidas
        final String[] SALIDAS = {"A_Consultar_HorarioE", "V_Consultar_HorarioE"};
        final int SALIDA_0 = 0;
        final int SALIDA_1 = 1;
        ActionErrors errors = new ActionErrors();
        int salida = SALIDA_0;
        EliminarHorario fHorario = (EliminarHorario)form;
        DataBaseManager dbms = DataBaseManager.getInstance();
        boolean eliminar = dbms.eliminarHorario(fHorario);
        if ( eliminar ) {
            salida = SALIDA_0;
        } else {
            errors.add("horario", new ActionMessage("errors.horario.asoc"));
            saveErrors(request,errors);
            salida = SALIDA_1;
        }
        return mapping.findForward(SALIDAS[salida]);
    }



}